﻿/*
 * Created by SharpDevelop.
 * User: IEscarro
 * Date: 8/25/2009
 * Time: 9:25 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using Miming.Model;
using Miming.Util;

namespace Miming.Gui
{
	/// <summary>
	/// Description of VendorForm.
	/// </summary>
	public partial class VendorForm : BaseForm
	{
		public VendorForm() : this(new Vendor())
		{
			
		}
		
		public VendorForm(Vendor v)
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			Model = v;
		}
		
		protected override void OnModelChanged(EventArgs e)
		{
			base.OnModelChanged(e);
			Vendor v = Model as Vendor;
			textBoxName.Text = v.Name;
			textBoxOpeningBalance.Text = v.OpeningBalance.ToString("0.00");
			dateTimePickerBalanceAsOf.Value = v.BalanceAsOf;
			textBoxCompanyName.Text = v.CompanyName;
			textBoxTitle.Text = v.LegalName.Title;
			textBoxLastName.Text = v.LegalName.Last;
			textBoxFirstName.Text = v.LegalName.First;
			textBoxMI.Text = v.LegalName.Middle;
			richTextBoxAddress.Text = v.Address;
			textBoxContact.Text = v.Contact;
			textBoxPhone.Text = v.Phone;
			textBoxFax.Text = v.Fax;
			textBoxAltPhone.Text = v.AltPhone;
			textBoxAltContact.Text = v.AltContact;
			textBoxEmail.Text = v.Email;
			textBoxCC.Text = v.CC;
			textBoxPrintOnCheckAs.Text = v.PrintOnCheckAs;
			textBoxAccountNo.Text = v.AccountNo;
			checkBoxInactive.Checked = v.Inactive;
		}
		
		void ButtonOkClick(object sender, EventArgs e)
		{
			Vendor v = Model as Vendor;
			v.Name = textBoxName.Text;
			v.OpeningBalance = ConvertUtility.ToDouble(textBoxOpeningBalance.Text);
			v.BalanceAsOf = dateTimePickerBalanceAsOf.Value;
			v.CompanyName = textBoxCompanyName.Text;
			v.LegalName = new Name(textBoxTitle.Text, textBoxLastName.Text, textBoxFirstName.Text, textBoxMI.Text);
			v.Address = richTextBoxAddress.Text;
			v.Contact = textBoxContact.Text;
			v.Phone = textBoxPhone.Text;
			v.Fax = textBoxFax.Text;
			v.AltPhone = textBoxAltPhone.Text;
			v.AltContact = textBoxAltContact.Text;
			v.Email = textBoxEmail.Text;
			v.CC = textBoxCC.Text;
			v.PrintOnCheckAs = textBoxPrintOnCheckAs.Text;
			v.AccountNo = textBoxAccountNo.Text;
			v.Inactive = checkBoxInactive.Checked;
			SessionFacade.SaveOrUpdateVendor(v);
			Close();
		}
		
		void ButtonCancelClick(object sender, EventArgs e)
		{
			Close();
		}
	}
}
